/**
 * 
 */
package au.com.blazer.scheduler.blossom.controller.paragraph;

import info.magnolia.cms.gui.dialog.DialogEdit;
import info.magnolia.cms.gui.dialog.DialogTab;
import info.magnolia.cms.util.AlertUtil;
import info.magnolia.module.blossom.annotation.DialogFactory;
import info.magnolia.module.blossom.annotation.Paragraph;
import info.magnolia.module.blossom.annotation.ParagraphDescription;
import info.magnolia.module.blossom.annotation.TabFactory;
import info.magnolia.module.blossom.annotation.TabOrder;
import info.magnolia.module.blossom.annotation.TabValidator;
import info.magnolia.module.blossom.dialog.TabBuilder;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * Controller defining a Simple Paragraph.
 * 
 * @author olad
 *
 */
@Paragraph(name = "simpleParagraph", value = "Simple Paragraph", dialog = "simple-dialog")
@ParagraphDescription("Simple Paragraph with title, text, description, image and link")
@DialogFactory("simple-dialog")
@TabOrder({ "Content", "Description" })
@Controller
public class SimpleParagraph {
	/**
     * Process the requests on URL /simpleParagraph
     *
     * @return
     */
    @RequestMapping("/simpleParagraph")
    public ModelAndView handleRequest() {
        return new ModelAndView();
    }
 
    /**
     * First Dialog Tab.
     *
     * @param tab
     */
    @TabFactory("Content")
    public void content(TabBuilder tab) {
        tab.addStatic("Title, image and link of the paragraph");
        tab.addEdit("title", "Title", "");
        tab.addFile("image", "Image", "Image 100 x 70 px");
        tab.addEdit("linkText", "Link Text", "");
        tab.addLink("link", "Link", "");
    }
 
    /**
     * Second Dialog Tab.
     *
     * @param tab
     */
    @TabFactory("Description")
    public void description(TabBuilder tab) {
        tab.addStatic("Description of the paragraph");
        tab.addFckEditor("description", "Description", "Rich text editor");
    }
 
    /**
     * First Tab Validator.
     *
     * @param dialogTab
     */
    @TabValidator("Content")
    public void validate(DialogTab dialogTab) {
        DialogEdit title = (DialogEdit) dialogTab.getSub("title");
        if (StringUtils.isEmpty(title.getValue())) {
            AlertUtil.setMessage("You need to enter a title !");
        }
    }
}
